package com.hao.tool.util.component.websocket.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;

/**
 * 使用线程池消费日志数据
 *
 * @author sawyerlsy
 * @date 2018-12-31
 * @since
 */
@Component
public class LogConsumer {


    @Autowired
    private SimpMessagingTemplate simpMessagingTemplate;

    /**
     * websocket日志推送地址
     */
    private static final String WEBSOCKET_LOG_TOPIC = "/topic/runningMsg";

    /**
     * 推送日志到 websocket可供订阅的地址中
     */
    public void pushLogger(LogMessage logMessage) {
        String message = logMessage.getLogTime() + " : " + logMessage.getMessage();
        simpMessagingTemplate.convertAndSend(WEBSOCKET_LOG_TOPIC, message);
    }

}
